package me.raih.hoi4;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

/**
 * @auther Raih
 * @Time 2021/5/7 13:49
 */
public class Aircraft {

    Logger logger = LoggerFactory.getLogger(Aircraft.class);

    /**
     *
     * @param id        飞机位置
     * @param flyNumber     飞机数量
     */
    public static void useJavaCode(Integer id,Integer flyNumber) throws Exception {

        if(id > 9 || id < 1){
            throw new Exception("飞机位置应该在1-9之间");
        }
        if(flyNumber < 800){
            throw new Exception("飞机数量要大于800，最好是800的整数   4000   8000  12000   20000");
        }

        //点击这么多次
        int time = flyNumber/800;
        System.out.println(time);
        //获取机器人对象
        Robot robot = new Robot();
        //设置延迟3秒
        robot.delay(3000);
        //放置飞机
        for (int i = 0; i < time; i++) {
            //鼠标移动到添加飞机位置
//            robot.mouseMove(360*2,(80+(-10))*2);
            robot.mouseMove(505,195);       //台式机
//            robot.mouseMove(510,190);  //笔记本
            //按下
            pressAndRelease(robot);
            //输出ID值
            System.out.println("ID是"+id);
            String name = "";
            if(id == 4 || id == 5 || id == 6){
                name = "yes";
                //如果是支援机
                System.out.println("我被执行了。。。");
                //鼠标移动到拉的位置
                robot.mouseMove(690*2,(296+80)*2);
                //按下鼠标左键
                robot.mousePress(InputEvent.BUTTON1_MASK);
                //拉下来
                robot.mouseMove(690*2,(390+80)*2);
                //释放鼠标
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
                //加延迟
                robot.delay(100);
                //这个时候ID就应该是第一个了
                id -= 3;
            }else if(id == 7 ){
                name = "ok";
                //鼠标移动到拉的位置
                robot.mouseMove(528*2,(205+80)*2);
                //按下鼠标左键
                robot.mousePress(InputEvent.BUTTON1_MASK);
                //拉下来
                robot.mouseMove(528*2,(240+80)*2);
                //释放鼠标
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
                //加延迟
                robot.delay(500);
                id-=6;
            }

            System.out.println("现在ID是"+id);

            //鼠标移动到id位置
//            robot.mouseMove(640*2,(280-60+id*60+80)*2);      //台式机
//            robot.mouseMove(880,595-83+83*id);      //笔记本
            robot.mouseMove(1310,785-83+83*id);
            for (int j = 0; j < 8; j++) {
                pressAndRelease(robot);
            }
            if(name.equals("yes")){
                id+=3;
            }else if(name.equals("ok")){
                id+=6;
            }
            //移动到OK位置
//            robot.mouseMove(700*2,(450+80)*2);
//            robot.mouseMove(960,810);        //笔记本
            robot.mouseMove(1400,1000);      //台式机
            //完成
            pressAndRelease(robot);
        }
        //再次释放shift
        robot.keyRelease(KeyEvent.VK_SHIFT);
    }

    /**
     * 带着shift的鼠标按下抬起方法
     * @param robot
     * @throws AWTException
     */
    private static void  pressAndRelease(Robot robot) throws AWTException {
        //键盘按下shift  16
        robot.keyPress(KeyEvent.VK_SHIFT);
        //按下鼠标左键
        robot.mousePress(InputEvent.BUTTON1_MASK);
        //释放鼠标左键
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        //释放shift按键
//            robot.keyRelease(16);
        robot.keyPress(KeyEvent.VK_SHIFT);
        //设置延迟0.5秒
        robot.delay(100);
    }

}
